package cn.ibizlab.odoo.core.odoo_gamification.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Igamification_goal_definition;
import cn.ibizlab.odoo.core.odoo_gamification.domain.Gamification_goal_definition;
import cn.ibizlab.odoo.core.odoo_gamification.filter.Gamification_goal_definitionSearchContext;
import cn.ibizlab.odoo.core.odoo_gamification.service.IGamification_goal_definitionService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[游戏化目标定义] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Gamification_goal_definitionServiceImpl implements IGamification_goal_definitionService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Igamification_goal_definitionClientService gamification_goal_definitionClientService;

    @Override
    public Gamification_goal_definition get(Integer id) {
        Igamification_goal_definition clientModel = gamification_goal_definitionClientService.createModel();
        clientModel.setId(id);
        gamification_goal_definitionClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Gamification_goal_definition get(Gamification_goal_definition gamification_goal_definition) {
        Gamification_goal_definition retgamification_goal_definition = this.get(gamification_goal_definition.getId()) ;
    	BeanCopier copier=BeanCopier.create(retgamification_goal_definition.getClass(), gamification_goal_definition.getClass(), false);
        copier.copy(retgamification_goal_definition, gamification_goal_definition, null);
        return gamification_goal_definition ;
    }

    @Override
    public boolean update(Gamification_goal_definition gamification_goal_definition) {
        boolean bOk = false ;
        Igamification_goal_definition clientModel = this.convert2Model(gamification_goal_definition,null);
        gamification_goal_definitionClientService.update(clientModel) ;
        this.convert2Domain(clientModel,gamification_goal_definition) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public boolean create(Gamification_goal_definition gamification_goal_definition) {
        boolean bOk = false ;
        Igamification_goal_definition clientModel = this.convert2Model(gamification_goal_definition,null);
        gamification_goal_definitionClientService.create(clientModel) ;
        this.convert2Domain(clientModel,gamification_goal_definition);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void createBatch(List<Gamification_goal_definition> gamification_goal_definitions, int batchSize) {

                        //gamification_goal_definitionClientService.createBatch(gamification_goal_definitions,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Igamification_goal_definition clientModel = gamification_goal_definitionClientService.createModel();
        clientModel.setId(id);
        gamification_goal_definitionClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public void updateBatch(List<Gamification_goal_definition> gamification_goal_definitions, int batchSize) {

        //gamification_goal_definitionClientService.updateBatch(gamification_goal_definitions,batchSize) ;

    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //gamification_goal_definitionClientService.removeBatch(gamification_goal_definitions) ;

    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Gamification_goal_definition> searchDefault(Gamification_goal_definitionSearchContext context) {
        List<Gamification_goal_definition> list = new ArrayList<Gamification_goal_definition>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_goal_definition> clientModelList = gamification_goal_definitionClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_goal_definition clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_goal_definition>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Gamification_goal_definition> selectByOdoo_create(Integer id){
        Gamification_goal_definitionSearchContext context = new Gamification_goal_definitionSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_goal_definition> list = new ArrayList<Gamification_goal_definition>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_goal_definition> clientModelList = gamification_goal_definitionClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_goal_definition clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_goal_definition>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Gamification_goal_definition> selectByOdoo_write(Integer id){
        Gamification_goal_definitionSearchContext context = new Gamification_goal_definitionSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Gamification_goal_definition> list = new ArrayList<Gamification_goal_definition>();
        Page<cn.ibizlab.odoo.core.client.model.Igamification_goal_definition> clientModelList = gamification_goal_definitionClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Igamification_goal_definition clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Gamification_goal_definition>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Igamification_goal_definition convert2Model(Gamification_goal_definition domain , Igamification_goal_definition model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = gamification_goal_definitionClientService.createModel() ;
        }

         if(domain.getSuffixDirtyFlag())
            model.setSuffix(domain.getSuffix());
         if(domain.getBatch_distinctive_fieldDirtyFlag())
            model.setBatch_distinctive_field(domain.getBatch_distinctive_field());
         if(domain.getMonetaryDirtyFlag())
            model.setMonetary(domain.getMonetary());
         if(domain.getConditionDirtyFlag())
            model.setCondition(domain.getCondition());
         if(domain.getCompute_codeDirtyFlag())
            model.setCompute_code(domain.getCompute_code());
         if(domain.getComputation_modeDirtyFlag())
            model.setComputation_mode(domain.getComputation_mode());
         if(domain.getAction_idDirtyFlag())
            model.setAction_id(domain.getAction_id());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getDomainDirtyFlag())
            model.setDomain(domain.getDomain());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getField_idDirtyFlag())
            model.setField_id(domain.getField_id());
         if(domain.getRes_id_fieldDirtyFlag())
            model.setRes_id_field(domain.getRes_id_field());
         if(domain.getBatch_modeDirtyFlag())
            model.setBatch_mode(domain.getBatch_mode());
         if(domain.getModel_idDirtyFlag())
            model.setModel_id(domain.getModel_id());
         if(domain.getDescriptionDirtyFlag())
            model.setDescription(domain.getDescription());
         if(domain.getField_date_idDirtyFlag())
            model.setField_date_id(domain.getField_date_id());
         if(domain.getDisplay_modeDirtyFlag())
            model.setDisplay_mode(domain.getDisplay_mode());
         if(domain.getFull_suffixDirtyFlag())
            model.setFull_suffix(domain.getFull_suffix());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getBatch_user_expressionDirtyFlag())
            model.setBatch_user_expression(domain.getBatch_user_expression());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Gamification_goal_definition convert2Domain( Igamification_goal_definition model ,Gamification_goal_definition domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Gamification_goal_definition();
        }

        if(model.getSuffixDirtyFlag())
            domain.setSuffix(model.getSuffix());
        if(model.getBatch_distinctive_fieldDirtyFlag())
            domain.setBatch_distinctive_field(model.getBatch_distinctive_field());
        if(model.getMonetaryDirtyFlag())
            domain.setMonetary(model.getMonetary());
        if(model.getConditionDirtyFlag())
            domain.setCondition(model.getCondition());
        if(model.getCompute_codeDirtyFlag())
            domain.setCompute_code(model.getCompute_code());
        if(model.getComputation_modeDirtyFlag())
            domain.setComputation_mode(model.getComputation_mode());
        if(model.getAction_idDirtyFlag())
            domain.setAction_id(model.getAction_id());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getDomainDirtyFlag())
            domain.setDomain(model.getDomain());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getField_idDirtyFlag())
            domain.setField_id(model.getField_id());
        if(model.getRes_id_fieldDirtyFlag())
            domain.setRes_id_field(model.getRes_id_field());
        if(model.getBatch_modeDirtyFlag())
            domain.setBatch_mode(model.getBatch_mode());
        if(model.getModel_idDirtyFlag())
            domain.setModel_id(model.getModel_id());
        if(model.getDescriptionDirtyFlag())
            domain.setDescription(model.getDescription());
        if(model.getField_date_idDirtyFlag())
            domain.setField_date_id(model.getField_date_id());
        if(model.getDisplay_modeDirtyFlag())
            domain.setDisplay_mode(model.getDisplay_mode());
        if(model.getFull_suffixDirtyFlag())
            domain.setFull_suffix(model.getFull_suffix());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getBatch_user_expressionDirtyFlag())
            domain.setBatch_user_expression(model.getBatch_user_expression());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
